package com.project.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.EventBean;
import com.project.service.EventService;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.time.LocalDate;

@Controller
@RequestMapping("event")
public class EventController {

    @Resource
    private EventService eventService;

    //显示所有事件信息
    @RequestMapping("findAllEvent")
    @ResponseBody
    public IPage<EventBean> findAllEvent(
            @RequestParam(value = "pageNo", defaultValue = "1") int pageNo,
            @RequestParam(value = "pageSize", defaultValue = "3") int pageSize) {
        return eventService.findAllEvent(pageNo, pageSize);
    }


    //添加事件
    @RequestMapping("addEvent")
    @ResponseBody
    public String addEvent(EventBean eventBean,int areaId) {
        eventService.addEvent(eventBean,areaId);
        return "ok";
    }


    //根据事件id查询事件详细信息
    @RequestMapping("findId")
    @ResponseBody
    public EventBean findId(@Param("eventId") int eventId) {
        return eventService.findId(eventId);
    }


    //申请专家会商
    @RequestMapping("updateConsult")
    @ResponseBody
    public String updateConsult(@Param("eventId")int eventId) {
        eventService.updateConsult(eventId);
        return "ok";
    }


    //根据事件id去修改灾情状况、防治方案
    @RequestMapping("updateEvent")
    @ResponseBody
    public String updateEvent(int eventId, String eventStage, String eventControl) {
        eventService.updateEvent(eventId, eventStage, eventControl);
        return "ok";
    }


    //模糊查询
    @RequestMapping("findName")
    @ResponseBody
    public IPage<EventBean> findName( @RequestParam(value = "pageNo", defaultValue = "1") int pageNo,
                                      @RequestParam(value = "pageSize", defaultValue = "3") int pageSize,
                                      String eventName, String eventStage,
                                    String address, LocalDate startTime,
                                    LocalDate endTime) {
        return eventService.findName(pageNo,pageSize,eventName, eventStage, address, startTime, endTime);
    }
}
